package com.self.match.model;

import com.self.common.param.Order;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * @version v1.0
 * @ClassName: 合并订单
 * @Description:
 * @Author: Mac
 * @Date: 2022/9/3 21:36
 */
public class MergeOrder {

    /**
     * @Title: 合并的订单形成一个有序链表
     */
    private LinkedList<Order> orders = new LinkedList<>();

    /**
     * @Title: 依次向后追加
     */
    public void add(Order order){
        orders.addLast(order);
    }

    /**
     * @Title: 从头获取
     */
    public Order get(){
        return orders.get(0);
    }

    public int size() {
        return orders.size();
    }

    public BigDecimal getPrice() {
        return orders.get(0).getPrice();
    }

    public Iterator<Order> iterator() {
        return orders.iterator();
    }

    public BigDecimal getTotalAmount() {
       return orders.stream().map(Order::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
    }

}
